home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
macify13.shr
/
macify.hqx
/
Source
/
Macify Code
/
call_macify.c
next >
Wrap
Text File
|
1991-03-15
|
3KB
|
101 lines
/* A little "pre-call" I added to allow file handling */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define F_OK 1
#define rindex strrchr
#include <quickdraw.h>
#include <StdFilePkg.h>
#include <EventMgr.h>
#include <FileMgr.h>
#include <string.h>
#include <pascal.h>
#include <stdlib.h>
#define STRLEN 256 /* kludge */
void call_macify(stuff_to_do)
int stuff_to_do;
{
int getfile(char *);
short access(char *, short); /* Pascal string */
FILE *fp, *dfp, *fopen(); /* input file pointer and dest file
* pointer */
char Macfile[STRLEN]; /* file name gotten from user prompt */
char Macoutfile[STRLEN]; /* file name for use as output */
FInfo finfo; /* for setting this file's finder info. */
printf("\nWelcome to MACIFY.\n");
if (getfile(Macfile) == FALSE) {
printf("No selection made.\n");
return; }
if (NULL == (fp = fopen(Macfile, "r"))) {
(void) printf("Error opening input file %s\n", Macfile);
}
/* Now we have a file to work with -- Macfile */
/* Use string catenation to come up with an output file */
strcpy(Macoutfile, Macfile);
strcat(Macoutfile, ".out"); /* Send output */
if (stuff_to_do == 1) /* UNIX -> Mac? */
printf("UNIX File: %s ==> Mac File: %s\nConversion in progres...\n",
Macfile, Macoutfile);
else if (stuff_to_do == 2) /* Mac -> UNIX? */
printf("Mac File: %s ==> UNIX File: %s\nConversion in progress...\n",
Macfile, Macoutfile);
macify(stuff_to_do, Macfile, Macoutfile); /* actually do it */
}
int
getfile (reply)
char *reply;
{
Point where;
SFReply frommac;
SFTypeList whatTypes;
whatTypes[0] = 'TEXT';
where.h = 75; where.v = 50;
SFGetFile (where, (StringPtr)"\p", 0L, 1, &whatTypes, 0L, &frommac);
if (frommac.good) {
SetVol ((StringPtr)"\p", frommac.vRefNum);
PtoCstr((char *)frommac.fName);
strcpy (reply, (char *)frommac.fName);
return (TRUE);
}
else return (FALSE);
}
/*
** access
**
** takes two arguments, either of which can be null.
** returns 0 if the file exists, -1 if it doesn't exist.
**
*/
short
access(name, vRefNum)
char *name; /* Pascal string */
short vRefNum;
{
FInfo info;
OSErr err;
Str255 NotUsed;
GetVol(NotUsed, &vRefNum);
CtoPstr(name);
err = GetFInfo((StringPtr)name, vRefNum, &info);
PtoCstr(name);
if (err == fnfErr)
return -1; /* file exists. */
else if (err == noErr)
return 0; /* file doesn't exist */
else
{
printf("Error %d when trying to find file %s\n", err, name);
return 0; /* file doesn't exist */
}
}